import { ElMessage } from 'element-plus'

import createRequest from "./request.js";
// const request = createRequest("http://mall.itanychw.online:8888/api/v2/");
const request = createRequest(process.env.VUE_APP_AJAX);
const send = function (options = {}) {
    options.headers = options.headers?options.headers:{};
    options.headers.Authorization = sessionStorage.getItem("token");
    return request(options)
                // 业务处理
                .then(( { data,meta } )=>{
                    if(meta.status<400){
                        ElMessage.success(meta.msg)
                        return Promise.resolve(data);
                    }else{
                        ElMessage.error(meta.msg);
                        return Promise.reject(meta);
                    }
                })
}

const login = function (data = {}) {
    return request({
        url: "login",
        method: "post",
        data
    })
}

const getLeftMenu = function () {
    // return request({
    //     url:"menus",
    //     method:"get"
    // })
    return send({
        url: "menus",
        method: "get"
    })
}

export default {
    login, getLeftMenu
}
